import platform from "@src/platform";
import qs from "qs";
import {getRootWindow} from "@src/util/dom";
import {t} from "@src/locales";
import {continuePaying} from "@src/api/SettingApi";
import {getRootWindowInitData} from "@src/util/window";
import dingTalk from "@src/util/dingtalk";

// 查询钉钉支付地址
async function toContinuePaying(orderId) {
    try {
        const DingTalkPC = getRootWindow(window).DingTalkPC;
        if (!dingTalk.inDingTalk) {
            platform.toast(t('common.base.rechargeModel.rechargeTip'),'warning')
            return;
        }
        let url = await continuePaying({orderId})
        DingTalkPC.biz.util.openSlidePanel({
            url,
            onSuccess: function (result) {
                console.log(result)
            },
            onFail: function (err) {
                console.log(err)
            }
        })
    } catch (e) {
        console.error(e)
    }
}

//充值
export function payHandle(orderId){
    if(getRootWindowInitData().tenantType !== 0) {
        platform.openLink(`/api/paycenter/outside/page/commodity/continue/alipay?${qs.stringify({orderId})}`)
    }else {
        toContinuePaying(orderId)
    }

}